from django.db import models
from django.contrib.auth.models import User


class Profile(models.Model):

    FAMILY_STATUS = [
        ('don\'t want male', 'аа-ее тупые деффки меня заебали'),
        ('don\'t want woman', 'все мужыки козлы'),
        ('love', 'любофь маркофь'),
    ]

    user = models.OneToOneField(User, on_delete=models.CASCADE)
    date_of_birth = models.DateTimeField(blank=True, null=True)
    photo = models.ImageField(upload_to="users/%Y%m%d", blank=True, null=True)
    family_status = models.CharField(max_length=35, choices=FAMILY_STATUS, blank=True, null=True)
    favorite_phrase = models.CharField(max_length=500, blank=True, null=True)
    last_online = models.DateTimeField(blank=True, null=True)

    class Meta:

        verbose_name = 'Профиль'
        verbose_name_plural = 'Профиль'


    def __str__(self):

        return f'Profile for user {self.user.username}'


class Contact(models.Model):

    not_subscriber = models.ForeignKey(User, on_delete=models.CASCADE, related_name='rel_from_set')
    subscriber = models.ForeignKey(User, on_delete=models.CASCADE, related_name='rel_to_set')
    created = models.DateTimeField(auto_now_add=True, db_index=True)

    class Meta:

        ordering = ('-created',)

    def __str__(self):

        return '{} subscribed to {}'.format(self.subscriber, self.not_subscriber)


User.add_to_class('subscribers', models.ManyToManyField('self',
                                                        through=Contact,
                                                        related_name='subscriptions',
                                                        symmetrical=False))
